﻿using System;
using System.Collections.Generic;
using System.Linq;
using Abp.Dependency;
using pandx.Mulan.Authorization.Users.Importing.Dto;
using pandx.Mulan.DataImExPorting.Excel;
using pandx.Mulan.Dto;
using pandx.Mulan.Storage;

namespace pandx.Mulan.Authorization.Users.Importing
{
    public class InvalidUserExporter:NpoiExcelExporterBase,IInvalidUserExporter,ITransientDependency
    {
        public InvalidUserExporter(ITempFileCacheManager tempFileCacheManager) : base(tempFileCacheManager)
        {
        }

        public FileDto ExportToExcel(List<ImportUserDto> userListDtos)
        {
            return CreateExcelPackage("没有导入成功用户列表_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + ".xlsx",
                excelPackage =>
                {
                    var sheet = excelPackage.CreateSheet("没有导入成功用户列表");
                    AddHeader(sheet,
                        "用户名",
                        "姓名",
                        "错误原因"
                    );
                    AddObjects(sheet,2,userListDtos,
                        _=>_.UserName,
                        _=>_.Name,
                        _=>_.Exception
                    );

                    for (var i = 0; i < 3; i++)
                    {
                        sheet.AutoSizeColumn(i);
                    }
                });
        }
    }
}
